#include "tmp75.h"
#include "stm32f4xx_hal.h"
#include <stdio.h>
extern I2C_HandleTypeDef hi2c1;

void tmp75_init(void) {
	uint8_t tmp[3]; 
	//tmp[0] = 144 & 0xFE;
	tmp[0] = (1 & 0x00FF);
	tmp[1] = 0x60;
  HAL_I2C_Master_Transmit(&hi2c1, 0x49<<1, (uint8_t *)&tmp, 2, 1000);
}

float tmp75_read(void) {
	uint8_t tmp[3]; 
	tmp[0] = 0;
	//tmp[1] = (1 & 0x00FF);
	//tmp[2] = 144 | 0x01;
	HAL_I2C_Master_Transmit(&hi2c1, 0x49<<1, (uint8_t *)&tmp, 1, 1000);
	HAL_I2C_Master_Receive(&hi2c1, 0x49<<1, (uint8_t *)&tmp, 2, 1000);

    uint16_t value = tmp[0];
    uint16_t t = tmp[1];
		value = value << 8;
		value = value + t;
    float temp = (value>>4)*0.0625;
		return temp;
}
